﻿using Dealin.Code;
using Dealin.Data.Extensions;
using Dealin.Domain._03_Entity.PublicManage;
using Dealin.Domain.Entity.InStock;
using Dealin.Domain.IRepository.InStock;
using Dealin.Repository.InStock;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dealin.Application.InStock
{
    public  class PlanApp
    {
        private IPlanRepository service = new PlanRepository(); 
        public DapperDbHelper db = new DapperDbHelper();

        public List<PlanEntity> GetList(string keyword = "")
        {
            var expression = ExtLinq.True<PlanEntity>();
            if (!string.IsNullOrEmpty(keyword))
            { 
                try
                { 
                    expression = expression.And(t => t.F_FileName==(keyword));
                    expression = expression.Or(t => t.F_Description==(keyword));
                }
                catch  
                { 
                }
            }
            return service.IQueryable(expression).OrderByDescending(p=>p.F_CreatorTime).ToList();
        } 
        
        public PlanEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public void DeleteForm(string keyValue)
        {

            service.Delete(t => t.F_Id == keyValue);
        }
        public void SubmitForm(PlanEntity meterEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                meterEntity.Modify(keyValue);
                service.Update(meterEntity);
            }
            else
            {
                meterEntity.Create();
                meterEntity.F_IsRunning = false;
                meterEntity.F_EnabledMark = true;
                service.Insert(meterEntity);
            }
        }
    }
}
